﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using HomeBuyerTools.FinanceProperties;
using Microsoft.Advertising.Mobile.UI;
using HomeBuyerTools.ViewModels;

namespace HomeBuyerTools.Views.CompareLoansByTerm
{
    public partial class CompareLoansByTerm : PhoneApplicationPage
    {
      
        private SolidColorBrush adcontrolborder = new SolidColorBrush(Colors.Transparent);
        Custom objCustom = new Custom();
        Settings savadata = new Settings();
        public CompareLoansByTerm()
        {
            InitializeComponent();
            LoadPivotThemes();

          

        }
      
        private void LoadPivotThemes()
        {
            LayoutRoot.Background = Custom.getPivotBackground(); ;
            
        }
        private void ApplicationBarCalculate_Click(object sender, EventArgs e)
        {
            if (TxtPrincipalBalance.Text != "")
            {
                txtblkprincipalbalanceValidation.Visibility = Visibility.Collapsed;

                if (TxtInterestRate.Text != "")
                    NavigationService.Navigate(new Uri("/Views/Result/ResultPage.xaml?sectionId=3&pb=" + TxtPrincipalBalance.Text + "&ir=" + TxtInterestRate.Text, UriKind.Relative));
                else
                {
                    txtblkinterestrateValidation.Text = "*Required";
                    txtblkinterestrateValidation.Visibility = Visibility.Visible;
                }
            }
            else
            {

                txtblkprincipalbalanceValidation.Text = "*Required";
                txtblkprincipalbalanceValidation.Visibility = Visibility.Visible;

            }
        }

       


        private void TxtInterestRate_LostFocus(object sender, RoutedEventArgs e)
        {

            savadata.AddInterest(Convert.ToDouble(TxtInterestRate.Text),0);

        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            //TxtInterestRate.Text = savadata.loadInterest();
             Visibility darkBackgroundVisibility = (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"];

             if (darkBackgroundVisibility == Visibility.Visible)
             {
                 //Theme is Dark
             }

             else
             {
                 //Theme is Light
                 TxtPrincipalBalance.MouseEnter += TxtPrincipalBalance_MouseEnter;
                 TxtPrincipalBalance.MouseLeave += TxtPrincipalBalance_MouseLeave;
                 TxtInterestRate.MouseEnter += TxtInterestRate_MouseEnter;
                 TxtInterestRate.MouseLeave += TxtInterestRate_MouseLeave;

             }
            List<SettingsProperties> prop = savadata.loadInterest();
            foreach (SettingsProperties irate in prop)
            {
                TxtInterestRate.Text = (irate.InterestRate).ToString();
                TxtPrincipalBalance.Text = (irate.MortgagePrincipal).ToString();
            }
           
                
           
        }

        void TxtInterestRate_MouseLeave(object sender, MouseEventArgs e)
        {
            TxtInterestRate.Foreground = new SolidColorBrush(Colors.Black);
        }

        void TxtInterestRate_MouseEnter(object sender, MouseEventArgs e)
        {
            TxtInterestRate.Foreground = new SolidColorBrush(Colors.White);
        }

        void TxtPrincipalBalance_MouseLeave(object sender, MouseEventArgs e)
        {
            TxtPrincipalBalance.Foreground = new SolidColorBrush(Colors.Black);
        }

        void TxtPrincipalBalance_MouseEnter(object sender, MouseEventArgs e)
        {
            TxtPrincipalBalance.Foreground = new SolidColorBrush(Colors.White);
        }

        private void TxtPrincipalBalance_LostFocus(object sender, RoutedEventArgs e)
        {
            savadata.AddInterest(0,Convert.ToDouble(TxtPrincipalBalance.Text));
           
        }

        private void imgTitle_MouseEnter(object sender, MouseEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/Result/ResultPage.xaml?sectionId=4&", UriKind.Relative));
        }


        
    }
}